package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.GetCategoryHandler;
import com.cungmua.app.model.request.GetCategoryRequest;
import com.cungmua.app.model.response.GetCategoryResponse;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/17/14.
 */
public class GetCategoryTask extends AuthenticatedTask<GetCategoryRequest, Void, GetCategoryResponse> {
    private final GetCategoryHandler handler;
    private final Context context;

    public GetCategoryTask(Context context, GetCategoryHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected GetCategoryResponse doInBackground() throws RetrofitError {
        GetCategoryRequest request = params[0];

        return service.getCategoryList(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(GetCategoryResponse getCategoryResponse) {
        handler.onCategoryList(getCategoryResponse);
    }
}
